#include <bits/stdc++.h>
using namespace std;
stack <int> a;
int n, k;
int main()
{
	cin >> n >> k;
	int dip = 1, size = 0;
	for(int i = 1; i <= n; i++)
	{
		size++;
		if(dip * k > n)
			break;
		dip *= k;
	}
	int o = 0;
	dip *= k;
	for(int i = 1; i <= size; i++)
	{
		dip /= k;
		int p;
		if(o + n - (n - o) % dip < n){
			p = (n - o) / dip;
			o += n - (n - o) % dip;
		}
		a.push(p);
		cout << dip << " " << p << " " << o << endl;
	}
	for(int i = 1; i <= size; i++)
	{
		int s = a.top();
		cout << s;
		a.pop();
	}
	return 0;
}